<template>
	<view class="container">
		<pyh-nv :config="config"></pyh-nv>
		<!-- <image :src="baseurl+'user/renzhengbg.png?v=1.0'" class="bg"></image> -->
		<view class="content">
			<view class="scrollBox">
				<view class="labelBox">
					<view class="labelLeft">
					</view>
					<text class="lebelText">项目名称</text>
				</view>
				<view class="xiangmuBox">
					<uni-data-select :clear="false" v-model="xiangmuIndex" :localdata="xiangmuArray"
						@change="changeXiangmu" placeholder="请选择"></uni-data-select>
				</view>
				<view class="labelBox">
					<view class="labelLeft">
					</view>
					<text class="lebelText">住宅信息</text>
				</view>
				<view class="zhuzhaiBox1">
					<image
						:src="zhuzhaiType==1?'https://miantou.guguan.net/img/user/selected.png':'https://miantou.guguan.net/img/user/select.png'"
						class="select" @click="changeType(1)"></image>
					<text class="shangye" :class="zhuzhaiType==1?'activeType':''" @click="changeType(1)">商业</text>
					<image
						:src="zhuzhaiType==2?'https://miantou.guguan.net/img/user/selected.png':'https://miantou.guguan.net/img/user/select.png'"
						class="select" @click="changeType(2)"></image>
					<text class="zhuzhai" :class="zhuzhaiType==2?'activeType':''" @click="changeType(2)">住宅</text>
				</view>
				<view class="zhuzhaiBox">
					<!-- <input type="text" class="dong" v-model="dong" />
					<text class="zhuzhaiText">栋</text>
					<input type="text" class="danyuan" v-model="danyuan" />
					<text class="zhuzhaiText">单元</text>
					<input type="text" class="hao" v-model="hao" />
					<text class="zhuzhaiText">号</text> -->
					<uni-data-select :clear="false" class="zhuzhaiSel" v-model="dongIndex" :localdata="dong"
						@change="changedong" placeholder="栋"></uni-data-select>
					<uni-data-select :clear="false" class="zhuzhaiSel" v-model="danyuanIndex" :localdata="danyuan"
						@change="changedanyuan" placeholder="单元"></uni-data-select>
					<uni-data-select :clear="false" class="zhuzhaiSel" v-model="louIndex" :localdata="lou"
						@change="changelou" placeholder="楼"></uni-data-select>
					<uni-data-select :clear="false" class="zhuzhaiSel" v-model="haoIndex" :localdata="hao"
						@change="changehao" placeholder="号"></uni-data-select>
				</view>
				<view class="labelBox">
					<view class="labelLeft">
					</view>
					<text class="lebelText">业主姓名</text>
				</view>
				<view class="nameBox">
					<input type="text" class="name" v-model="name" placeholder="请输入业主姓名" />
				</view>
				<view class="labelBox">
					<view class="labelLeft">
					</view>
					<text class="lebelText">业主关系<text class="lebelText1">（产权人请选择业主，非产权人请选择家属）</text></text>
				</view>
				<view class="renshuBox">
					<uni-data-select :clear="false" v-model="numIndex" :localdata="numArray" @change="changeNum"
						placeholder="请选择"></uni-data-select>
				</view>
				<view class="labelBox">
					<view class="labelLeft">
					</view>
					<text class="lebelText">手机号验证</text>
				</view>
				<view class="telBox">
					<input type="text" class="tel" v-model="tel" maxlength="11" placeholder="请输入本人手机号码" />
				</view>
				<view class="codeBox">
					<input type="text" class="code" v-model="code" maxlength="11" placeholder="请输入验证码" />
					<view class="sendCode" @click="sendCode()">
						{{sendCodeMsg}}
					</view>
				</view>

				<!-- <view class="idcardBox">
					<input type="text" class="name" v-model="idcard" placeholder="请输入业主身份证号码" maxlength="18"/>
				</view>
				<view class="nameBox1">
					<input type="text" class="name" v-model="name1" placeholder="请输入用户姓名" />
				</view>
				<view class="renshuBox">
					<uni-data-select :clear="false" v-model="numIndex" :localdata="numArray" @change="changeNum"
						placeholder="请选择"></uni-data-select>
				</view>
				<view class="telBox">
					<input type="text" class="tel" v-model="tel" maxlength="11" placeholder="请输入用户电话" />
				</view>-->
				<view class="submit" @click="submit">
					提交
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				baseurl: this.$baseurl,
				config: {
					// back: {
					// 	hide: true
					// },
					bgColor: "#4E97AD",
					title: "业主认证",
					color: '#ffffff'
				},
				zhuzhaiType: 0,
				name: '',
				name1: '',
				idcard: '',
				tel: '',
				num: '',
				xiangmuIndex: '',
				xiangmuArray: [],
				dong: [],
				dongIndex: '',
				danyuan: [],
				danyuanIndex: '',
				lou: [],
				louIndex: '',
				hao: [],
				haoIndex: '',
				code: '',
				numIndex: '',
				numArray: [{
						value: 0,
						text: "本人"
					},
					{
						value: 1,
						text: "亲属"
					},
				],
				sendCodeMsg: '发送验证码',
				time: 60,
				residence: {
					building: '',
					unit: '',
					floor: '',
					num: ''
				}
			}
		},
		onShow() {
			// this.$request.get(`Community/submit_status`).then(res => {
			// 	this.isTab = res.data.data;
			// })
		},
		onLoad(options) {
			this.$request.get(`project/project_index`).then(res => {
				console.log(res.data.data);
				for (let i = 0; i < res.data.data.length; i++) {
					let obj = {};
					obj.value = res.data.data[i].id;
					obj.text = res.data.data[i].name;
					obj.building = res.data.data[i].building;
					obj.unit = res.data.data[i].unit;
					obj.floor = res.data.data[i].floor;
					obj.num = res.data.data[i].num;
					this.xiangmuArray.push(obj)
				}
			})
		},
		methods: {
			sendCode() {
				if (this.tel == '') {
					this.$u.toast('请填写手机号码')
					return;
				}
				if (this.sendCodeMsg != '发送验证码') {
					this.$u.toast('请稍后获取')
					return;
				}
				//获取短信 api/sms/send
				this.$request.post(`sms/send`, {
					mobile: this.tel,
					key: 'BDSJHM'
				}).then(res => {
					if (res.data.code > 0) {
						let timer;
						timer = setInterval(() => {
							if (this.time > 0) {
								this.time--;
								console.log(this.time);
								this.sendCodeMsg = this.time + 's后重新获取';
							} else {
								clearInterval(timer);
								this.sendCodeMsg = '发送验证码';
							}
						}, 1000);
					} else {
						this.$u.toast(res.data.msg)
					}
				})


			},
			changeType(num) {
				this.zhuzhaiType = num;
			},
			changeNum(e) {
				console.log(e);
				this.numIndex = e;
			},
			changeXiangmu(e) {
				console.log(e);
				const index = this.xiangmuArray.findIndex(obj => obj.value === e);
				if (index !== -1) {
					console.log(`第一个值为 "${e}" 的对象在数组中的索引是: ${index}`);
					console.log(this.xiangmuArray[index].building);
					this.dongNum = this.xiangmuArray[index].building;
					this.danyuanNum = this.xiangmuArray[index].unit;
					this.louNum = this.xiangmuArray[index].floor;
					this.haoNum = this.xiangmuArray[index].num;
					for (let i = 0; i < this.dongNum; i++) {
						let obj = {};
						obj.value = i + 1;
						obj.text = i + 1;
						this.dong.push(obj);
					}
					for (let i = 0; i < this.danyuanNum; i++) {
						let obj = {};
						obj.value = i + 1;
						obj.text = i + 1;
						this.danyuan.push(obj);
					}
					for (let i = 0; i < this.louNum; i++) {
						let obj = {};
						obj.value = i + 1;
						obj.text = i + 1;
						this.lou.push(obj);
					}
					for (let i = 0; i < this.haoNum; i++) {
						let obj = {};
						obj.value = i + 1;
						obj.text = i + 1;
						this.hao.push(obj);
					}
				} else {
					console.log(`值为 "${e}" 的对象未找到`);
				}
				this.xiangmuIndex = e;
			},
			changedong(e) {
				console.log(e);
				this.dongIndex = e;
			},
			changedanyuan(e) {
				console.log(e);
				this.danyuanIndex = e;
			},
			changelou(e) {
				console.log(e);
				this.louIndex = e;
			},
			changehao(e) {
				console.log(e);
				this.haoIndex = e;
			},
			submit() {
				if (this.xiangmuIndex == '') {
					this.$u.toast('请选择项目')
					return;
				}
				if (this.zhuzhaiType == 0) {
					this.$u.toast('请选择住宅类型')
					return;
				}
				if (this.dongIndex === '' || this.danyuanIndex === '' || this.louIndex === '' || this.haoIndex === '') {
					this.$u.toast('请选择完整住宅信息')
					return;
				}
				if (this.name == '') {
					this.$u.toast('请输入业主姓名')
					return;
				}
				// if (this.name1 == '') {
				// 	this.$u.toast('请输入用户姓名')
				// 	return;
				// }
				console.log(this.numIndex)
				if (this.numIndex === '') {
					this.$u.toast('请选择业主关系')
					return;
				}
				// if (this.tel == '') {
				// 	this.$u.toast('请填写手机号码')
				// 	return;
				// }
				// if (this.code == '') {
				// 	this.$u.toast('请填写验证码')
				// 	return;
				// }
				// 预约
				let haoNum = this.hao[this.haoIndex-1].value;
				if (haoNum < 10) {
					haoNum = '0' + haoNum;
				}
				this.$request.post(`user/proprietor_certification`, {
					proprietor_name: this.name,
					project_id: this.xiangmuIndex,
					residence: this.dong[this.dongIndex-1].value + '栋' + this.danyuan[this.danyuanIndex-1].value +
						'单元' + this.lou[this.louIndex-1].value + '楼' + haoNum + '号',
					relation: this.numArray[this.numIndex].text,
					phone: this.tel,
					sms_code: this.code,
					type: this.zhuzhaiType
				}).then(res => {
					if (res.data.code > 0) { //预约成功
						this.$u.toast('提交成功')
					} else {
						this.$u.toast(res.data.msg)
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	.activeType {
		color: #4f97ad;
	}

	.zhuzhaiSel {
		width: 155rpx;
		height: 88rpx;
		background-color: #fff;
		border-radius: 10rpx;
		margin-right: 10rpx;
	}

	.labelBox {
		width: 100%;
		display: flex;
		margin-top: 40rpx;
		align-items: center;

		.labelLeft {
			width: 8rpx;
			height: 25rpx;
			background-color: #4E97AD;
		}

		.lebelText {
			display: block;
			margin-left: 30rpx;
		}

		.lebelText1 {
			margin-left: 10rpx;
			color: #4E97AD;
			font-size: 26rpx;
		}
	}

	.submit {
		width: 500rpx;
		height: 90rpx;
		border-radius: 10rpx;
		margin-left: 125rpx;
		margin-top: 100rpx;
		margin-bottom: 100rpx;
		font-size: 28rpx;
		text-align: center;
		color: #FAFAFA;
		line-height: 90rpx;
		background-color: #4E97AD;
	}

	.idcardBox {
		width: 674rpx;
		height: 88rpx;
		margin-top: 115rpx;
		margin-left: 39rpx;
		border-radius: 10rpx;
		display: flex;
		align-items: center;
		background-color: #fff;

		.name {
			width: 100%;
			height: 100%;
			margin-left: 10rpx;
			border: none;
			text-align: left;
			font-size: 26rpx;
			color: #000000;
		}
	}

	.nameBox1 {
		width: 674rpx;
		height: 88rpx;
		margin-top: 115rpx;
		margin-left: 39rpx;
		border-radius: 10rpx;
		display: flex;
		align-items: center;
		background-color: #fff;

		.name {
			width: 100%;
			height: 100%;
			margin-left: 10rpx;
			border: none;
			text-align: left;
			font-size: 26rpx;
			color: #000000;
		}
	}

	.nameBox {
		width: 674rpx;
		height: 88rpx;
		margin-top: 40rpx;
		margin-left: 39rpx;
		border-radius: 10rpx;
		display: flex;
		align-items: center;
		background-color: #fff;

		.name {
			width: 100%;
			height: 100%;
			margin-left: 10rpx;
			border: none;
			text-align: left;
			font-size: 26rpx;
			color: #000000;
		}
	}

	.zhuzhaiBox1 {
		position: relative;
		margin-top: 55rpx;
		display: flex;
		align-items: center;

		.select {
			width: 32rpx;
			height: 32rpx;
			margin-left: 40rpx;
		}

		.shangye {
			font-size: 24rpx;
			margin-left: 35rpx;
			margin-right: 40rpx;
		}

		.zhuzhai {
			font-size: 24rpx;
			margin-left: 35rpx;
		}
	}

	.zhuzhaiBox {
		position: relative;
		width: 674rpx;
		height: 88rpx;
		margin-top: 40rpx;
		margin-left: 39rpx;
		border-radius: 10rpx;
		display: flex;
		align-items: center;

		// background-color: red;
		.zhuzhaiText {
			display: block;
			margin-left: 20rpx;
		}

		.dong {
			width: 120rpx;
			height: 100%;
			border: none;
			text-align: center;
			font-size: 26rpx;
			color: #000000;
			background-color: #fff;
			border-radius: 10rpx;
		}

		.danyuan {
			width: 120rpx;
			height: 100%;
			border: none;
			text-align: center;
			font-size: 26rpx;
			color: #000000;
			background-color: #fff;
			margin-left: 65rpx;
			border-radius: 10rpx;
		}

		.hao {
			width: 120rpx;
			height: 100%;
			border: none;
			text-align: center;
			font-size: 26rpx;
			color: #000000;
			background-color: #fff;
			margin-left: 65rpx;
			border-radius: 10rpx;
		}
	}

	.telBox {
		position: relative;
		width: 674rpx;
		height: 88rpx;
		margin-top: 40rpx;
		margin-left: 39rpx;
		border-radius: 10rpx;
		display: flex;
		align-items: center;
		background-color: #fff;

		.tel {
			position: absolute;
			width: 100%;
			height: 100%;
			left: 10rpx;
			border: none;
			text-align: left;
			font-size: 26rpx;
			color: #000000;
		}
	}

	.codeBox {
		width: 674rpx;
		height: 88rpx;
		margin-top: 25rpx;
		margin-left: 39rpx;
		border-radius: 10rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;

		.code {
			width: 440rpx;
			height: 100%;
			padding-left: 10rpx;
			border: none;
			text-align: left;
			font-size: 26rpx;
			color: #000000;
			background-color: #fff;
			border-radius: 10rpx;
		}

		.sendCode {
			width: 194rpx;
			height: 100%;
			line-height: 88rpx;
			padding-left: 10rpx;
			border: none;
			text-align: center;
			font-size: 26rpx;
			color: #fff;
			background-color: #fff;
			border-radius: 10rpx;
			background-color: #4E97AD;
		}
	}

	.uni-stat__select {
		height: 100% !important;
		width: 96%;
	}

	.uni-select {
		padding: 0;
		padding-left: 0;
		border: none !important;
	}

	.uni-select__input-placeholder {
		color: #fff;
		text-align: left;

	}

	.uni-icons {
		display: none;
	}

	.uni-select__input-text {
		color: #000 !important;
		text-align: left;
	}

	.xiangmuBox,
	.timeBox,
	.renshuBox {
		width: 674rpx;
		height: 82rpx;
		margin-left: 39rpx;
		margin-top: 40rpx;
		background-color: #ffffff !important;
		border-radius: 10rpx;
		padding-left: 10rpx;

		.renshu {
			margin-left: 35rpx;
			width: 100%;
			height: 100%;
			font-size: 22rpx;
			text-align: left;
			color: #fff;
		}


	}

	.menuBox {
		position: absolute;
		width: 670rpx;
		height: 90rpx;
		background-color: #C49A69;
		margin-top: 1330rpx;
		left: 40rpx;

		.menuText {
			width: 100%;
			height: 100%;
			line-height: 90rpx;
			text-align: center;
			font-size: 30rpx;
			color: #ffffff;
		}
	}


	// .scrollBox {
	// 	width: 100%;
	// 	height: 100vh;
	// 	overflow-y: scroll;
	// }

	.container {
		width: 100%;
		height: 100vh;
		overflow-y: scroll;
		background-color: #F5F7FB;
	}

	// .content {
	// 	width: 100%;
	// 	height: 100vh;
	// 	overflow-y: scroll;
	// }
</style>